package wireless.frequent.action;

import java.util.List;

import cm.util.action.list.ListActionSupport;

import wireless.frequent.pojo.Frequent;
import wireless.frequent.service.FrequentLengthService;
public class FrequentLengthList {
	
	private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
	.getLog(ListActionSupport.class);
	/**
	 * 频繁串长度
	 */
	private int length;
	/**
	 * 跳转参数
	 */
	private String forward;

	/**
	 * 获得默认的分页大小
	 */
	protected int pageSize = 15;

	/**
	 * 总页数
	 */
	protected int totalPages = -1;

	/**
	 * 当前页
	 */
	protected int currentPage = -1;

	/**
	 * 上一页
	 */
	private int previousPage = 1;

	/**
	 * 下一页
	 */
	private int nextPage = 1;

	/**
	 * 总记录条数
	 */
	protected long totalRows = -1;

	/**
	 * 列表数据
	 */
	protected List<Frequent> list;
	FrequentLengthService service = new FrequentLengthService();
    public String execute() throws Exception{
    		length = getLength();
    		totalRows=service.sizeAll(length);
    		initPageProperties();
    		list=service.findAllDesc(length,"desc",currentPage, pageSize);
    		switch(length)
    		{
    		case 4:
    			return "frequent_4_success";
			case 8:
    			return "frequent_8_success";
    		case 16:
    			return "frequent_16_success";
    		default:
    			return "failed";
    		}
    }
    
	/**
	 * 初始化页面属性<br>
	 * 必须在已获得totalRows值之后再调用该函数<br>
	 * 调用方式为：<br>
	 * 
	 * 给totalRows赋值<br>
	 * 调用initPageProperties(form)方法<br>
	 * 给list赋值<br>
	 * 调用initAttribute(request)方法<br>
	 * 
	 * 该方法在调用查询语句之前调用<br>
	 * pageSize为系统默认的分页的大小，如要更改pageSize，应在掉用setPageSize方法后再调用该方法<br>
	 * 
	 * 
	 */
	protected void initPageProperties() {

		if (totalRows == -1) {
			log.error("没有初始化totalRows参数！");
		}

		
		currentPage = currentPage <= 1 ? 1 : currentPage;

		totalPages = (totalRows % pageSize == 0) ? ((int) (totalRows / pageSize))
				: ((int) (totalRows / pageSize + 1));

		currentPage = currentPage >= totalPages ? totalPages : currentPage;

		previousPage = currentPage > 1 ? currentPage - 1 : 1;

		nextPage = currentPage < totalPages ? currentPage + 1 : totalPages;

	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public String getForward() {
		return forward;
	}

	public void setForward(String forward) {
		this.forward = forward;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPreviousPage() {
		return previousPage;
	}

	public void setPreviousPage(int previousPage) {
		this.previousPage = previousPage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public long getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(long totalRows) {
		this.totalRows = totalRows;
	}

	public List<Frequent> getList() {
		return list;
	}

	public void setList(List<Frequent> list) {
		this.list = list;
	}

	public FrequentLengthService getService() {
		return service;
	}

	public void setService(FrequentLengthService service) {
		this.service = service;
	}

	public static org.apache.commons.logging.Log getLog() {
		return log;
	}
	
}
